<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/19
 * Time: 09:49
 */

namespace App\Http\Controllers\MiniProgram;


use App\Http\Controllers\BaseController;
use App\Http\Logics\MiniProgram\CartLogic;
use App\Http\Traits\CartTrait;

class CartController extends BaseController
{
    use CartTrait;

    /**
     * @SWG\Post(
     *     path="/cart/create",
     *     tags={"Cart"},
     *     description="添加购物车",
     *     operationId="createCart",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="goods_id",
     *         in="query",
     *         description="商品ID",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="num",
     *         in="query",
     *         description="商品数量",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createCart()
    {
        $loginSession = $this->loginSession;
        $goods_id = $this->goods_id;
        $num = $this->num;
        $data = [
            'loginSession' => $loginSession,
            'goods_id' => $goods_id,
            'num' => $num
        ];
        $response = CartLogic::createCart($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/cart/delete",
     *     tags={"Cart"},
     *     description="删除购物车",
     *     operationId="deleteCart",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cart_id",
     *         in="query",
     *         description="购物车ID",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function deleteCart()
    {
        $cart_id = $this->cart_id;
        $data = [
            'cart_id' => $cart_id
        ];
        $response = CartLogic::deleteCart($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/cart/list",
     *     tags={"Cart"},
     *     description="删除购物车",
     *     operationId="getCartList",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getCartList()
    {
        $loginSession = $this->loginSession;
        $data = [
            'loginSession' => $loginSession
        ];
        $response = CartLogic::getCartList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/cart/changeNum",
     *     tags={"Cart"},
     *     description="更新购物车商品数量",
     *     operationId="changeCartNum",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cart_id",
     *         in="query",
     *         description="购物车ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="num",
     *         in="query",
     *         description="改变数量",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function changeCartNum()
    {
        $num = $this->num;
        $cart_id = $this->cart_id;
        $data = [
            'num' => $num,
            'cart_id' => $cart_id
        ];
        $response = CartLogic::changeCartNum($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}